<?php
/**
 * LoggerService class
 *
 * @Name 日志业务层
 * @Desc 方法描述
 * @Author Pekey
 * @Date 2020-08-13
 */
class LoggerService extends TP_Service
{
    public function __construct()
    {
        parent::__construct();
        $this->load->Model("PModel/Logger_model");
    }

    /**
     * saveLogger function
     *
     * @Name 保存logger
     * @Desc 方法描述
     * @Author Pekey
     * @Date 2020-08-13
     * @param [type] $actionname
     * @param [type] $desc
     * @param string $uuid
     * @return void
     */
    public function saveLogger($actionname, $desc, $uuid = "")
    {
        $data = array();
        $data['ip'] = sys_get_client_ip();
        $data['actionpath'] = $actionname;
        $data['actiondesc'] = $desc;
        $data['uuid'] = $uuid;
        $data['created'] = time();
        $this->cache->redis->set(redisLogger($data['ip'], $data['created']),$data);
        $this->updateLogger(redisLogger($data['ip'], $data['created']));
    }

    /**
     * updateLogger function
     *
     * @Name 更新日志到数据表
     * @Desc 方法描述
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author Pekey
     * @Date 2020-08-13
     * @return void
     */
    /*public function updateLogger()
    {
        $_datas = $this->cache->redis->keys(redisLogger());
        $ret = array();
        foreach ($_datas as $key => $value) {
            array_push($ret, $value);
        }
        $this->Logger_model->add($datas);
        $this->cache->redis->delete($_datas);
    }*/

    /**
     * [ description]
     * @Name        updateLogger
     * @Description 更新日志到数据表
     * @Author      LiAnXu
     * @Date 2021-01-09 13:11:50 星期六
     * @param       $name redies名称
     * @return      [type]                   [description]
     */
    public function updateLogger($name)
    {
        $_datas = $this->cache->redis->get($name);
        $ret = array();
        foreach ($_datas as $key => $value) {
            array_push($ret, $value);
        }
        $this->Logger_model->add($_datas);
        $this->cache->redis->delete($_datas);
    }
}
